<%--
  Created by IntelliJ IDEA.
  User: parttime
  Date: 2017/8/19
  Time: 下午16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="resources.jsp" %>


<html>
<head>
    <title>聊天群列表</title>
</head>
<body>
<div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">查询条件</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline">
                <div class="form-group">
                    <%--<label for="name">群名称：</label>--%>
                    <input type="text" class="form-control" id="name" name="name"  placeholder="群名称">
                </div>
                <div class="form-group">
                    <%--<label for="status">状态：</label>--%>
                    <select id="status" name="status" class="form-control">
                        <option value = "">群状态</option>
                        <option value ="0">冻结</option>
                        <option value ="1">正常</option>
                        <option value ="2">解散</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="button" id="btn-search" class="btn btn-info">查询</button>
                    <button type="button" class="btn btn-reset btn-default">清空</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="ems_table_content">
    <div class="panel panel-default">
        <div class="panel-heading">聊天群列表</div>
        <div id="toolbar">
            <div class="form-inline" role="form">
                <%--<button type="button" id="chatgroup_add" class="btn btn-outline btn-success">--%>
                    <%--<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>--%>
                    <%--添加--%>
                <%--</button>--%>
                <%--<button type="button" id="chatgroup_modify" class="btn btn-outline btn-primary">--%>
                    <%--<i class="glyphicon glyphicon-edit" aria-hidden="true"></i>--%>
                    <%--修改--%>
                <%--</button>--%>
                <%--<button type="button" id="chatgroup_delete" class="btn btn-outline btn-danger">--%>
                    <%--<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>--%>
                    <%--删除--%>
                <%--</button>--%>
                <button type="button" id="chatgroup_active" class="btn btn-outline btn-warning">
                    <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                    激活
                </button>
                <button type="button" id="chatgroup_freeze" class="btn btn-outline btn-default">
                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                    冻结
                </button>
            </div>
        </div>
        <table id="chatGroupTable"
               data-url="/ems/chatgroup/pagination"
               data-show-export="true">
            <thead>
            <tr>
                <th data-field="state" data-checkbox="true"></th>
                <th data-field="name">群名称</th>
                <th data-field="owner">群主</th>
                <th data-field="administrator">管理员</th>
                <th data-field="create_time">创建时间</th>
                <th data-field="status" data-formatter="statusFormat">状态</th>
            </tr>
            </thead>

        </table>
    </div>
</div>

<script>
    $(function () {
        $("#chatGroupTable").bootstrapTable(
            {
                showColumns: true,
                showRefresh: true,
                showToggle: true,
                search: true,
                sidePagination: "server",
                pagination: true,
                clickToSelect: true,
                pageList: [5, 10, 20, 50, 100, 200],
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                paginationFirstText: "首页",
                paginationLastText: "尾页",
                toolbar: "#toolbar",

                onPostHeader: function () {
                    $("th").css({"background-color": "#f5f5f5"});
                }
            }
        )

        //搜索
        $("#btn-search").on("click",function () {
            search(getQueryParams());
        });

        //激活
        $("#chatgroup_active").on("click",function () {
            var selectRows =  $('#chatGroupTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要激活的记录");
                return;
            }

            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行数据编辑");
                return;
            }

            $.confirmAlert("你确定要激活该记录吗",function(){
                $.emsAjax({
                    data:{id:selectRows[0].id},
                    type:"POST",
                    url:"/ems/chatgroup/activate",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#chatGroupTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });

        //冻结
        $("#chatgroup_freeze").on("click",function () {
            var selectRows =  $('#chatGroupTable').bootstrapTable('getSelections');
            if (selectRows.length == 0) {
                $.errorAlert("请选择要冻结的记录");
                return;
            }
            debugger;

            if (selectRows.length > 1) {
                $.errorAlert("暂时不支持多行记录的冻结");
                return;
            }

            $.confirmAlert("你确定要冻结该记录吗",function(){
                $.emsAjax({
                    data:{id:selectRows[0].id},
                    type:"POST",
                    url:"/ems/chatgroup/freeze",
                    success:function(resp) {
                        if (resp.status == "000") {
                            $.alert(resp.message);
                            search("#chatGroupTable",getQueryParams());
                        }else {
                            $.errorAlert(resp.message);
                        }
                    }
                });
            });
        });
    })

</script>


<script>
    function statusFormat(srcValue) {
        if (srcValue == 0) {
            return "<span style='color: red;font-weight: bold' >冻结</span>";
        } else if(srcValue == 1) {
            return "<span style='color: #3cb371;font-weight: bold'>正常</span>";
        } else if (srcValue == 2) {
            return "<span style='color: #cd6217;font-weight: bold'>解散</span>";
        }
    }

    function search(params) {
        var queryParams = {"query":params};
        $('#chatGroupTable').bootstrapTable('refresh', queryParams);
    }

</script>

</body>
</html>
